package com.example.qxfw.jtyb.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.example.qxfw.common.entity.zy.Traffic;
import com.example.qxfw.common.entity.zy.TrafficWeatherSta;
import com.example.qxfw.jtyb.mapper.TrafficMapper;
import com.example.qxfw.jtyb.service.JtybcxService;
import com.example.qxfw.ybzz.mapper.TrafficWeatherStaMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class JtybcxServiceImpl implements JtybcxService {
    @Autowired
    private TrafficWeatherStaMapper trafficWeatherStaMapper;
    @Autowired
    private TrafficMapper trafficMapper;



    @Override
    public List<TrafficWeatherSta> selectTypeOfTrafficWeatherSta() {
        return trafficWeatherStaMapper.selectList(new LambdaQueryWrapper<TrafficWeatherSta>()
                .select(TrafficWeatherSta::getRoadtype)
                .groupBy(TrafficWeatherSta::getRoadtype));
    }

    @Override
    public List<Traffic> selectByRoadDateTypeNtimesTimecharOfTraffic(String roadType, Date announcedtime, Integer forecasttype, Integer ntimes) {
        return trafficMapper.selectList(new LambdaQueryWrapper<Traffic>()
                .eq(announcedtime != null, Traffic::getAnnouncedtime, announcedtime)
                .eq(forecasttype != 0, Traffic::getForecasttype, forecasttype)
                .eq(ntimes != 0, Traffic::getNtimes, ntimes)
                .apply(StringUtils.isNotBlank(roadType),
                        "trafficsid IN (SELECT stationid FROM traffic_weather_sta WHERE roadtype = {0})", roadType)
        );
    }
}
